﻿using B.S.DataBasic.Domain.GoodInfra;
using B.S.DataBasic.ErrorCode;
using B.S.DataBasic.Infrastructure.Implement;
using MediatR;

namespace B.S.DataBasic.Read.API.Application
{
    public class ListCommandHandler : IRequestHandler<ListCommand, APIResult<List<Traceabilitable>>>
    {
        private readonly IBaseRepository<Traceabilitable> traceRepostiroy;
        public ListCommandHandler(IBaseRepository<Traceabilitable> traceRepostiroy)
        {
            this.traceRepostiroy = traceRepostiroy;
        }

        public Task<APIResult<List<Traceabilitable>>> Handle(ListCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Traceabilitable>> result = new APIResult<List<Traceabilitable>>();
            result.Code=EnumCode.查询成功;
            result.Message=EnumCode.查询成功.ToString();

            var list = traceRepostiroy.GetAll().Where(x => x.TrId == request.TrId).ToList();
            result.Data = list;


            return Task.FromResult(result);
        }
    }
}
